# Contributor: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
# Maintainer: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
pkgname=c2rust
pkgver=0.18.0
pkgrel=1
pkgdesc="Transpile C99-compliant code to (unsafe) Rust code"
url="https://github.com/immunant/c2rust"
# riscv64: libc crate sup
# s390x: missing big endian support in c2rust-bitfields-derive
# ppc64le: tinycbor not packaged due to segfault in unit tests
arch="all !riscv64 !s390x !ppc64le"
license="BSD-3-Clause"
# Note: LLVM's CMake hooks check for presence of static libs and complain if
# they are missing. So they are needed for building even when linking
# dynamically
makedepends="
	cargo
	cargo-auditable
	clang17-dev
	clang17-static
	cmake
	libxml2-dev
	llvm17-dev
	llvm17-gtest
	llvm17-static
	ncurses-dev
	openssl-dev
	rust
	tinycbor-dev
	"
checkdepends="
	python3
	py3-plumbum
	py3-toml
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/immunant/c2rust/archive/refs/tags/v$pkgver.tar.gz
	0001-link-clang-dynamic.patch
	0002-use-system-tinycbor.patch
	df42b55eae9ecfd4380004a513a10526ef8776cf.patch
	"

# Unit tests all fail using rust 1.72.1 with:
#
#    error[E0554]: #![feature] may not be used on the stable release channel
#
# Eventually, unit tests should also run on stable rust
options="!check"

export CARGO_PROFILE_RELEASE_LTO="true"
export CARGO_PROFILE_RELEASE_PANIC="abort"
export CARGO_PROFILE_RELEASE_OPT_LEVEL="s"

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --release --frozen --package c2rust
}

check() {
	./scripts/test_translator.py tests
}

package() {
	mkdir -p "$pkgdir"/usr/bin "$pkgdir"/usr/lib
	for bin in c2rust c2rust-transpile; do
		install -D -m755 target/release/$bin -t "$pkgdir"/usr/bin/
	done
}

sha512sums="
16033110923d22d12c55bdd13aacbeb05b95a54b93b8eabf478b111e99fba6c523102e871f4812d35152a9c02fae39ee25307acdfbe6d7bef23113f5c9db8dde  c2rust-0.18.0.tar.gz
3bd7def407277482a33c5074388a10afadf1b40b3f09e2fc87e9942a802b65ca2ee356be56e4baa66d669c57dcfd52ef27d59e740f0c735eb09c03fbf21015bb  0001-link-clang-dynamic.patch
be29e0f4576301b64f5fc38684ddb90e469526be4ce8ef428feee0d5962748c428045dcb81635ff92e132daebb1fa1b338a81ce1ea13d02b802ec057d0653b93  0002-use-system-tinycbor.patch
34764bd19f927bff11e86a26f6826b0875abebfb78256d895d36e04cf16f9a98ac8672ba7de0891613112e3aef724c501045ab303093c3fcad135590c82f3506  df42b55eae9ecfd4380004a513a10526ef8776cf.patch
"
